#include<bits/stdc++.h>
#define int unsigned
using namespace std;
int n;
int s[53][53][53][53];
void Add(vector<int>& v)
{
	int cnt = 0;
	for(int i = 0;i < 4;i++)
		cnt += (v[i] > n);
	if(cnt > 1) return;
	for(int i = 0;i < 4;i++) if(!(cnt - (v[i] > n)))
	{
		int t = v[i];
		v[i] = 1;
		s[v[0]][v[1]][v[2]][v[3]]++;
		v[i] = t;
	}
	if(!cnt)
		s[v[0]][v[1]][v[2]][v[3]] -= 3;
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	freopen("c.in","r",stdin);
	freopen("c.out","w",stdout);
	cin >> n;
	int m;
	cin >> m;
	for(int i = 1;i <= m;i++)
	{
		vector<int> v;
		for(int j = 0;j < 4;j++)
		{
			int x;
			cin >> x;
			v.push_back(x + 1);
		}
		Add(v);
	}
	unsigned ans = 0;
	for(int i = 1;i <= n;i++)
		for(int j = 1;j <= n;j++)
			for(int k = 1;k <= n;k++)
				for(int t = 1;t <= n;t++)
					s[i][j][k][t] += s[i][j][k][t - 1];
	for(int i = 1;i <= n;i++)
		for(int j = 1;j <= n;j++)
			for(int k = 1;k <= n;k++)
				for(int t = 1;t <= n;t++)
					s[i][j][k][t] += s[i][j][k - 1][t];
	for(int i = 1;i <= n;i++)
		for(int j = 1;j <= n;j++)
			for(int k = 1;k <= n;k++)
				for(int t = 1;t <= n;t++)
					s[i][j][k][t] += s[i][j - 1][k][t];
	for(int i = 1;i <= n;i++)
		for(int j = 1;j <= n;j++)
			for(int k = 1;k <= n;k++)
				for(int t = 1;t <= n;t++)
					s[i][j][k][t] += s[i - 1][j][k][t];
	for(int i = 1;i <= n;i++)
		for(int j = 1;j <= n;j++)
			for(int k = 1;k <= n;k++)
				for(int t = 1;t <= n;t++)
					ans += (s[i][j][k][t] == m);
	cout << ans;
	return 0;
}